<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        html {
            height: 5000px;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: grey;
            padding: 10px;
            margin: 50px;
            position: absolute;
            left: 100px;
            top: 100px
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>
<script>

    // 偏移: 子元素相较于父元素的距离

    var box = document.querySelector(".box");

    // 自己计算 => 太麻烦
    // var leftVal = parseInt(window.getComputedStyle(box).marginLeft) + parseInt(window.getComputedStyle(box).left);
    // var topVal = parseInt(window.getComputedStyle(box).marginTop) + parseInt(window.getComputedStyle(box).top);
    // console.log(leftVal, topVal);

    // offsetLeft / offsetTop  左(上)偏移 (margin + position)
    console.log(box.offsetParent, box.offsetLeft, box.offsetTop);







</script>

</html>